﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace WindowsGame2
{
    public static class DebugView
    {
        private struct DebugObject
        {
            public float rotation;
            public Color color;
            public Rectangle rectangle;

        }
        private static Texture2D m_Pixel;

        private static Dictionary<String, DebugObject> m_objects = new Dictionary<String, DebugObject>();

        public static Texture2D Pixel
        {
            get { return m_Pixel; }
            set { m_Pixel = value; }
        }

        public static void Update(String a_name, Rectangle a_rect, Color a_color, float a_rotation)
        {
            DebugObject debugObject = new DebugObject();
            debugObject.rectangle = a_rect;
            debugObject.color = a_color;
            debugObject.rotation = a_rotation;

            if (!m_objects.ContainsKey(a_name))
            {
                m_objects.Add(a_name, debugObject);
            }
            else
            {
                m_objects[a_name] = debugObject;
            }
        }

        public static void Draw(SpriteBatch a_spriteBatch)
        {
            if (m_objects.Count > 0)
            {
                int borderWidth = 2;
                DebugObject obj;

                for (int i = 0; i < m_objects.Count; i++)
                {
                    obj = m_objects.Values.ElementAt(i);

                    //Problem with drawing att object origin
                    a_spriteBatch.Draw(Assets.Pixel, new Rectangle(obj.rectangle.Left, obj.rectangle.Top, borderWidth, obj.rectangle.Height),
                        null, obj.color, obj.rotation, Vector2.Zero, SpriteEffects.None, 1);
                    a_spriteBatch.Draw(Assets.Pixel, new Rectangle(obj.rectangle.Right, obj.rectangle.Top, borderWidth, obj.rectangle.Height),
                        null, obj.color, obj.rotation, Vector2.Zero, SpriteEffects.None, 1);
                    a_spriteBatch.Draw(Assets.Pixel, new Rectangle(obj.rectangle.Left, obj.rectangle.Top, obj.rectangle.Width, borderWidth),
                        null, obj.color, obj.rotation, Vector2.Zero, SpriteEffects.None, 1);
                    a_spriteBatch.Draw(Assets.Pixel, new Rectangle(obj.rectangle.Left, obj.rectangle.Bottom, obj.rectangle.Width, borderWidth),
                        null, obj.color, obj.rotation, Vector2.Zero, SpriteEffects.None, 1);
                }
            }
        }
    }
}
